/**
 * English Mass Unit Tests
 * Tests convert and toUnit for each Unit Type
 */

package cmsc495.mach2.test.unit.english;

import cmsc495.mach2.unit.english.EnglishMassUnit;
import junit.framework.TestCase;

/**
 * @author Michael Swann
 */

public class EnglishMassUnitValidation extends TestCase {

	// Amount of Error Allowed
	private static final double				DELTA					= 0.01;

	private static final double				OUNCES_VALUE			= 32000.0;
	private static final double				POUNDS_VALUE			= 2000.0;
	private static final double				STONES_VALUE			= 142.8571429789;
	private static final double				HUNDREDWEIGHTS_VALUE	= 20.0;
	private static final double				TONS_VALUE				= 1.0;
	private static final double				GRAMS_VALUE				= 907184.740760757;

	private static final double				values[]				= { OUNCES_VALUE, POUNDS_VALUE, STONES_VALUE, HUNDREDWEIGHTS_VALUE, TONS_VALUE, GRAMS_VALUE };
	private static final EnglishMassUnit[]	englishMassUnits		= EnglishMassUnit.values();

	public EnglishMassUnitValidation() {
	}

	@Override
	protected void setUp() throws Exception {
		super.setUp();
	}

	/**
	 * Test method for
	 * {@link mach2convert.englishunit.EnglishMassUnit#convert(double, mach2convert.englishunit.EnglishMassUnit)}
	 * .
	 */
	public final void testConvert() {
		for (int i = 0; i < englishMassUnits.length; i++) {
			for (int j = 0; j < englishMassUnits.length; j++) {
				double result = englishMassUnits[i].convert(values[j], englishMassUnits[j]);
				System.out.println("ASSERT: " + values[i] + " = " + result + " " + englishMassUnits[i] + ".convert(" + values[j] + ", " + englishMassUnits[j] + "))");
				assertEquals(values[i], result, DELTA);
			}
		}
	}

	/**
	 * Test method for
	 * {@link mach2convert.englishunit.EnglishMassUnit#toOunces(double)}.
	 */
	public final void testToOunces() {
		for (int i = 0; i < englishMassUnits.length; i++) {
			double result = englishMassUnits[i].toOunces(values[i]);
			System.out.println("ASSERT: " + OUNCES_VALUE + " = " + result + " " + englishMassUnits[i] + ".toOunces(" + values[i] + ") ");
			assertEquals(OUNCES_VALUE, result, DELTA);
		}
	}

	/**
	 * Test method for
	 * {@link mach2convert.englishunit.EnglishMassUnit#toPounds(double)}.
	 */
	public final void testToPounds() {
		for (int i = 0; i < englishMassUnits.length; i++) {
			double result = englishMassUnits[i].toPounds(values[i]);
			System.out.println("ASSERT: " + POUNDS_VALUE + " = " + result + " " + englishMassUnits[i] + ".toPounds(" + values[i] + ") ");
			assertEquals(POUNDS_VALUE, result, DELTA);
		}
	}

	/**
	 * Test method for
	 * {@link mach2convert.englishunit.EnglishMassUnit#toStones(double)}.
	 */
	public final void testToStones() {
		for (int i = 0; i < englishMassUnits.length; i++) {
			double result = englishMassUnits[i].toStones(values[i]);
			System.out.println("ASSERT: " + STONES_VALUE + " = " + result + " " + englishMassUnits[i] + ".toStones(" + values[i] + ") ");
			assertEquals(STONES_VALUE, result, DELTA);
		}
	}

	/**
	 * Test method for
	 * {@link mach2convert.englishunit.EnglishMassUnit#toHundredweights(double)}
	 * .
	 */
	public final void testToHundredweights() {
		for (int i = 0; i < englishMassUnits.length; i++) {
			double result = englishMassUnits[i].toHundredweights(values[i]);
			System.out.println("ASSERT: " + HUNDREDWEIGHTS_VALUE + " = " + result + " " + englishMassUnits[i] + ".toHundredweights(" + values[i] + ") ");
			assertEquals(HUNDREDWEIGHTS_VALUE, result, DELTA);
		}
	}

	/**
	 * Test method for
	 * {@link mach2convert.englishunit.EnglishMassUnit#toTons(double)}.
	 */
	public final void testToTons() {
		for (int i = 0; i < englishMassUnits.length; i++) {
			double result = englishMassUnits[i].toTons(values[i]);
			System.out.println("ASSERT: " + TONS_VALUE + " = " + result + " " + englishMassUnits[i] + ".toTons(" + values[i] + ") ");
			assertEquals(TONS_VALUE, result, DELTA);
		}
	}

	/**
	 * Test method for
	 * {@link mach2convert.englishunit.EnglishMassUnit#toGrams(double)}.
	 */
	public final void testToGrams() {
		for (int i = 0; i < englishMassUnits.length; i++) {
			double result = englishMassUnits[i].toGrams(values[i]);
			System.out.println("ASSERT: " + GRAMS_VALUE + " = " + result + " " + englishMassUnits[i] + ".toGrams(" + values[i] + ") ");
			assertEquals(GRAMS_VALUE, result, DELTA);
		}
	}
}